#!/bin/sh
# This regression test is a part of SIPp.
# -srtpcheck_debug in a directory where the SRTP debug file cannot be
# created: the call ends without a crash.
. "`dirname "$0"`/../functions"; init

# Root writes in a read-only directory: drop the capabilities.
nocaps=
if test "`id -u`" -eq 0; then
    setpriv --inh-caps=-all --bounding-set=-all true 2>/dev/null ||
        skip "root with no setpriv"
    nocaps="setpriv --inh-caps=-all --bounding-set=-all"
fi

sipp="`get_sipp`"
dir=`mktemp -d`
chmod 555 $dir
(cd $dir && exec $nocaps timeout -sKILL 15 "$sipp" -nostdin -sn uas \
    -i 127.0.0.1 -p 26150 -m 1 -srtpcheck_debug -timeout 10 \
    >/dev/null 2>&1) &
uas=$!
sleep 1
sippfg -sn uac -i 127.0.0.1 -p 26151 -m 1 127.0.0.1:26150 -timeout 10 \
    >/dev/null 2>&1
status=$?
wait $uas
uas_status=$?
chmod 755 $dir
rm -rf $dir

if test $uas_status -ne 0; then
    fail "UAS exited with $uas_status"
elif test $status -ne 0; then
    fail "UAC exited with $status"
else
    ok
fi
